package com.das.mechanic_base.adapter.alone;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.bean.alone.TestRecommendBean;

import java.util.ArrayList;
import java.util.List;

public class X3RecommendForYouAdapter extends RecyclerView.Adapter<X3RecommendForYouAdapter.RecommendViewHolder> {

    private Context mContext;
    private List<TestRecommendBean> mList;

    public X3RecommendForYouAdapter(Context mContext) {
        this.mContext = mContext;
        mList = new ArrayList<>();
    }
    public void setData(List<TestRecommendBean> list) {
        mList = list;
    }

    @NonNull
    @Override
    public X3RecommendForYouAdapter.RecommendViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new X3RecommendForYouAdapter.RecommendViewHolder(LayoutInflater.from(mContext).inflate(R.layout.x3_item_recommend_foryou,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull X3RecommendForYouAdapter.RecommendViewHolder holder, int position) {
        holder.itemView.setTag(position);
        holder.tv_name.setText(mList.get(position).name);
//        if(position == 3){
//            holder.rl_content.setBackgroundResource(R.drawable.bg_recommend_gradient);
//        }else {
//            holder.rl_content.setBackgroundResource(R.drawable.x3_bg_recommend_for_you);
//        }

//        holder.view.setVisibility(position + 1 == mList.size() ? View.GONE:View.VISIBLE);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class RecommendViewHolder extends RecyclerView.ViewHolder {
        private TextView tv_name;
        private RelativeLayout rl_content;
        public RecommendViewHolder(@NonNull View itemView) {
            super(itemView);
            tv_name = itemView.findViewById(R.id.tv_name);
            rl_content = itemView.findViewById(R.id.rl_content);
            itemView.setOnClickListener(v -> {
                if(ionItemClick != null){
                    String pos = v.getTag().toString();
                    System.out.println("位置"+pos);
                    ionItemClick.onItemClick(mList.get(Integer.parseInt(pos)));

                }
            });
        }
    }
    public interface IonItemClick{
        void onItemClick(TestRecommendBean testRecommendBean);
    }

    IonItemClick ionItemClick;

    public void setOnItemClick(IonItemClick ionItemClick){
        this.ionItemClick = ionItemClick;
    }

}
